package com.qf.zsq.service.impl;

import com.qf.entity.GoodsEntity;
import com.qf.entity.OrderEntity;
import com.qf.mapper.OrderMapper;
import com.qf.pojo.OrderPojo;
import com.qf.zsq.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements IOrderService {


    @Autowired
    OrderMapper orderMapper;
    @Override
    public OrderEntity createOrder(OrderEntity oe, Map<String, GoodsEntity> shopCar, String[] gids) {
        boolean b = orderMapper.addOrder(oe);
        if(b){
            GoodsEntity goodsEntity;
            for (String gid:gids){
                goodsEntity = shopCar.get(gid);
                orderMapper.addOrderDetail(oe.getOid(),gid,goodsEntity.getGoodsPrice()*goodsEntity.getGoodsNumber(),goodsEntity.getGoodsNumber());
            }
            return oe;
        }
        return null;
    }
    @Override
    public boolean addAddressToOrder(Integer addressId, String oid) {
        return orderMapper.addAddressToOrder(addressId,oid);
    }
    @Override
    public boolean upOstatus(String oid) {
        return orderMapper.upOstatus(oid);
    }

    @Override
    public OrderPojo selectOrder(String oid) {
        return orderMapper.selectOrder(oid);
    }

    @Override
    public boolean payMon(String oid) {
        return orderMapper.payMon(oid);
    }

    @Override
    public List<OrderPojo> selectOrderById(Integer cid) {
        return orderMapper.selectOrderById(cid);
    }
}
